package cn.hill4j.tool.spring.ext.iop.feign;

import cn.hill4j.tool.spring.ext.iop.IopContext;
import feign.Feign;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.openfeign.FeignClientProperties;
import org.springframework.cloud.openfeign.support.FeignHttpClientProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


/**
 * 改造feign成iopClient实现
 *
 * @author: hillchen
 * Date: 2023-02-13 15:29
 */
@Configuration
@ConditionalOnClass(Feign.class)
@EnableConfigurationProperties({ FeignClientProperties.class,
        FeignHttpClientProperties.class })
public class FeignIopAutoConfiguration {

    @Bean
    public IopContext feignIopContext() {
        return new IopContext();
    }

    @Configuration
    @ConditionalOnClass(name = "feign.hystrix.HystrixFeign")
    protected static class HystrixFeignTargeterConfiguration {
        @Bean
        @ConditionalOnMissingBean
        public FeignIopTargeter feignIopTargeter() {
            return new HystrixFeignIopTargeter();
        }

    }
}
